package com.lizy

import org.junit.Test

/**
 * 数值
 */
class NumberTest {
    @Test
    void testInteger() {
        println(num)
        //1. 加法运算
        def plus = 5 + 3;
        println('加法运算:' + plus);
        //2. 减法运算
        def minus = 5 - 3;
        println('减法运算：' + minus);
        //4. 乘法运算
        def multiply = 5 * 3;
        println('乘法运算：' + multiply);
        //5. 除法运算
        def divide = 5 / 3;
        println('除法运算：' + divide);
        //6. 取余运算
        def mod = 5   3;
        println('取余运算：' + mod);
    }

    @Test
    void testString() {
        println("-------测试Groovy中单引号、双引号、三引号----------");
        def age = 25;
        println('My age is ${age}'); //My age is ${age}
        println("My age is ${age}"); //My age is 25
        println("""My age is ${age}"""); //My age is 25
        println("My age is \${age}");//My age is ${age}
        println("""My age is \${age}""");//My age is ${age}

        println("-------测试Groovy中使用下标操作字符串----------");
        def str = "hello world";
        println(str[4]); //指定下标对应的某个字符
        println(str[-1]); //下标为-1，代表是最后一个字符
        println(str[1..2]); //..表示字符串的某个范围
        println(str[1..<3]); //..<表示小于某个区间
        println(str[4..2]); //可以逆序表示
        println(str[4,1,6]); //可以单独指定某几个下标

        println("-------测试字符串基本操作----------");

        def greeting = "hello world";
        def greeting2 = greeting - 'o world';
        println(greeting);
        println(greeting2);
        println(greeting.size());
        println(greeting2.size());

        println("-------字符串方法----------");
        

    }


    /**
     * 习题1
     */
    @Test
    public void test1() {
        def num1 = 123;
        def num2 = .123;
        def num3 = 0.123;
        def num4 = 10.0e4;
        def num5 = 10e4;
        println('num1' + ":" + num1);
        println('num2' + ":" + num2);
        println('num3' + ":" + num3);
        println('num4' + ":" + num4);
        println('num5' + ":" + num5);
    }

}
